package com.xuecheng.manage_cms.web.controller;

import com.xuecheng.api.cms.CmsPageControllerApi;
import com.xuecheng.framework.domain.cms.CmsPage;
import com.xuecheng.framework.domain.cms.request.QueryPageRequest;
import com.xuecheng.framework.domain.cms.response.CmsPageResult;
import com.xuecheng.framework.domain.cms.response.CmsPostPageResult;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.manage_cms.service.CmsPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Aniymx on 2018/12/16 19:46.
 *
 * 页面操作
 */
@RestController
@RequestMapping("/cms/page")
public class CmsPageController implements CmsPageControllerApi {
    /**
     * 注入pageService对象
     */
    @Autowired
    private CmsPageService pageService;

    /**
     * 查询所有
     */
    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findAll(@PathVariable("page") int page,
                                       @PathVariable("size") int size,
                                       QueryPageRequest queryPageRequest) {
        QueryResponseResult queryResponseResult = pageService.findAll(page, size, queryPageRequest);
        return queryResponseResult;
    }

    /**
     * 新增页面
     */
    @PostMapping("/add")
    public CmsPageResult addPage(@RequestBody CmsPage cmsPage) {
        return pageService.addPage(cmsPage);
    }

    /*根据id查询页面*/
    @GetMapping("/findById/{id}")
    public CmsPage findById(@PathVariable("id") String id) {
        return pageService.findById(id);
    }

    /*更新页面*/
    @PutMapping("/edit/{id}")
    public CmsPageResult updatePage(@PathVariable String id, @RequestBody CmsPage cmsPage) {
        return pageService.updatePage(id, cmsPage);
    }

    /*删除页面*/
    @DeleteMapping("/delete/{id}")
    public CmsPageResult deletePage(@PathVariable String id) {
        CmsPageResult cmsPageResult = pageService.deletePage(id);
        return cmsPageResult;
    }

    /*发布页面*/
    @PostMapping("/postPage/{pageId}")
    public CmsPageResult post(@PathVariable("pageId") String id) {
        return pageService.post(id);
    }
//保存页面
    @Override
    @PostMapping("/save")
    public CmsPageResult save(@RequestBody CmsPage cmsPage) {
        return pageService.save(cmsPage);
    }
//一键发布接口
    @Override
    @PostMapping("/postPageQuick")
    public CmsPostPageResult postPageQuick(@RequestBody CmsPage cmsPage) {
        return pageService.postPageQuick(cmsPage);
    }


}
